/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Interfaz.java
 *
 * Created on 26-feb-2013, 15:49:09
 */
package practica1compi;

import Compilador.NodoError;
import Compilador.lexico;
import Compilador.sintactico;
import java.awt.Desktop;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;

/**
 *
 * @author Ebert
 */
public class Interfaz extends javax.swing.JFrame {

    static public LinkedList<ecuacion> ecuaciones = new LinkedList<ecuacion>();
    static public LinkedList<String> operacioens = new LinkedList<String>();
    static public LinkedList<String> Imprimir = new LinkedList<String>();
    static public LinkedList<Variable> tablaDeSimbolos = new LinkedList<Variable>();

    Ventanamultiple ventanaMultimple = new Ventanamultiple(this);
    VentanaResultados ventanaResultados=new VentanaResultados(this);
    
    String nombre = "";
    String direccion_dearchivo = "";
    String texto = "";
    
    char hihiii ='?';
    
    public static LinkedList<NodoError> ListaDeErroresLexicos = new LinkedList<NodoError>();
    LinkedList<String> ListaDeToken = new LinkedList<String>();
    
    
    /** Creates new form Interfaz */
    public Interfaz() {
        initComponents();
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //Cerrar Ventana implicara apagra mi programa
        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent we) {
                Salir();
                
            }
        });
    }

    /**
     * metodo salir
     * @param ninguno
     * @return ningun balor pero dependiendo de como este el area de texto lo guardara
     * @exception ninguna
     */
    void Salir() {

        if (direccion_dearchivo.equals("") && Texto.getText().equals("")) {
            System.exit(0);
        }

        if (direccion_dearchivo.equals("")) {

            int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

            if (b == 1) {
                System.exit(0);
            }
            if (b == 0) {
                Guardar();
                System.exit(0);
            }

        } else {
            if (!Texto.getText().equals("")) {

                int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

                if (b == 1) {

                    System.exit(0);
                }
                if (b == 0) {
                    try {


                        FileWriter salida8 = new FileWriter(direccion_dearchivo);


                        salida8.write(Texto.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas

                        salida8.close();


                        System.exit(0);
                    } catch (IOException ooo) {
                        System.out.println("entro al catch");
                    }
                } else {
                    int ebert = JOptionPane.showConfirmDialog(null, "seguro que desea salir");

                    if (ebert == 1 || ebert == 2) {
                    } else {

                        System.exit(0);
                    }

                }
            }
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        Texto = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Texto.setColumns(20);
        Texto.setRows(5);
        jScrollPane1.setViewportView(Texto);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/play.GIF"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/nuevo.gif"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/abrir.JPG"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jMenu1.setText("File");

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/abrir.JPG"))); // NOI18N
        jMenuItem2.setText("Abrir");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jMenuItem3.setText("Guardar");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/guardar.gif"))); // NOI18N
        jMenuItem4.setText("Guardar Como");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/nuevo.gif"))); // NOI18N
        jMenuItem10.setText("Nuevo");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem10);

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/cerrar.gif"))); // NOI18N
        jMenuItem5.setText("Cerrar");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconos/play.GIF"))); // NOI18N
        jMenuItem1.setText("Correr");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem6.setText("Mostrar Ventana de Especificaciones");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuItem9.setText("Mostrar Errores");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem9);

        jMenuItem7.setText("Mostrar Ventana de Resultados");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem7);

        jMenuItem8.setText("Mostrar Ventana de Recuento");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem8);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 499, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE)
                    .addComponent(jButton4, 0, 0, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed



    


}//GEN-LAST:event_jMenuItem1ActionPerformed
    
void Guardar(String texto, String path) {
    try{
    File nuevo=new File(path);
FileWriter Guardax = new FileWriter(nuevo);
                Guardax.write(texto);
                Guardax.close();
    }catch (Exception e){
    
    }
}

void Guardar() {
        String Total;
        try {
            JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
            fc.showSaveDialog(this);

            File Guardar = fc.getSelectedFile();
            if (Guardar != null) {
                nombre = fc.getSelectedFile().getName();
                FileWriter Guardax = new FileWriter(Guardar);
                Total = Texto.getText();
                Guardax.write(Total);
                Guardax.close();
            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    /**
     * metodo guardar
     * @param niguno
     * @return realiza un nuevo archivo con lo uqe este en el texto
     * @exception lanza esta ecepcion IOException ioe
     */
    void Guardarw() {
        if (direccion_dearchivo.equals("")) {
            Guardar();
        } else {
            int b = JOptionPane.showConfirmDialog(null, "Desea guardar los cambios efectuados en el documento actual");

            if (b == 0) {
                try {


                    FileWriter salida11 = new FileWriter(direccion_dearchivo);


                    salida11.write(Texto.getText());//escribe cada caracter en el archivo adheriendo un parametro para diferenciarlo de los demas

                    salida11.close();



                } catch (IOException ooo) {
                }

            } else {
            }
        }
    }
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    Abrir();
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed

    this.Guardarw();
    // TODO add your handling code here:
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed

    this.Guardar();
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
    this.Salir();
}//GEN-LAST:event_jMenuItem5ActionPerformed

private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
    Texto.setText("");
    direccion_dearchivo = "";


}//GEN-LAST:event_jMenuItem10ActionPerformed



private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
String html="";

    html=this.GenerarHTMLerroresLexicos();
    this.Guardar(html, "Mostrar Errores.html");

    Runtime ejecutor = Runtime.getRuntime();
        try {
            File dd = new File("Mostrar Errores.html");
            Desktop d = Desktop.getDesktop();
            d.open(dd);
        } catch (IOException ex) {
            System.out.println("el maldito error");
        }
}//GEN-LAST:event_jMenuItem9ActionPerformed

String FinBasico="</body></html>";
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
ventanaMultimple.setVisible(true);
if(Lexico!=null){
 Lexico.HTML+=FinBasico;
ventanaMultimple.Actalizar(Lexico.HTML);
System.out.println(Lexico.HTML);
}
    this.setVisible(false);// TODO add your handling code here:

}//GEN-LAST:event_jMenuItem6ActionPerformed

private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
String HTMLS="";

//HTMLS+="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
//xmlns=\"http://www.w3.org/1999/xhtml\"
HTMLS+="<html>";
HTMLS+="<head>";
//HTMLS+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
HTMLS+="<title>Untitled Document</title>";
/*HTMLS+="<style>";
	HTMLS+="table{";
		
		HTMLS+="background:#000;";
		HTMLS+="color:#F9C;";
		HTMLS+="border: #700 solid 1px;";
	HTMLS+="}";
	HTMLS+="thead{";
		HTMLS+="background:#F39;";
		HTMLS+="padding: 3px 5px;";
		HTMLS+="color:#fff;";
		HTMLS+="font-size:1.2em;";
		HTMLS+="font-weight: bold;";
	HTMLS+="}";

	
	HTMLS+="td, th{";
		HTMLS+="border-bottom: #333 solid 1px;";
		HTMLS+="border-right:#333 solid 1px;";
	HTMLS+="}";
	HTMLS+="tr:nth-child(even){";
		HTMLS+="background:#222;";
	HTMLS+="}";
	HTMLS+="td:last-child,th:last-child{";
		
		HTMLS+="border-right:none;";
	HTMLS+="}";
	HTMLS+="tr:last-child td{";
		HTMLS+="border-bottom:none;";
	HTMLS+="}";
	HTMLS+="td,th{ margin: 0; padding: 3px 10px; vertical-align:top}";
HTMLS+="</style>";
 * 
 */
HTMLS+="</head>";

HTMLS+="<body>";
HTMLS+="<table cellpadding=\"0\" cellspacing=\"0\" >";
	HTMLS+="<thead>";
    	HTMLS+="<tr>";
        	HTMLS+="<th>No</th>";
        	HTMLS+="<th>Componente Lexico</th>";
        	HTMLS+="<th>Recuento</th>";
        	
        HTMLS+="</tr>";
    HTMLS+="</thead>";
    HTMLS+="<tbody>";
    	HTMLS+="<tr>";
        	HTMLS+="<td>1</td>";
        	HTMLS+="<td>Tag de Inicializacion</td>";
        	HTMLS+="<td>"+Lexico.cinicio+"</td>     ";   	
        HTMLS+="</tr>";
        HTMLS+="<tr>";
        	HTMLS+="<td>2</td>";
        	HTMLS+="<td>Tag de Finalizacion</td>";
        	HTMLS+="<td>"+Lexico.cfin+"</td>      ";  	
        HTMLS+="</tr>";
        HTMLS+="<tr>";
        	HTMLS+="<td>3</td>";
        	HTMLS+="<td>funcion \"Print\"</td>";
        	HTMLS+="<td>"+Lexico.cprints+"</td>";
        HTMLS+="</tr>";
        HTMLS+="<tr>";
        	HTMLS+="<td>4</td>";
       	  HTMLS+="<td>Funcion \"Graficar\"</td>";
       	  HTMLS+="<td>"+Lexico.cgraficar+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>5</td>";
        	HTMLS+="<td>Funcion \"Operacion\"</td>";
        	HTMLS+="<td>"+Lexico.coperaciones+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>6</td>";
        	HTMLS+="<td>Variables</td>";
        	HTMLS+="<td>"+Lexico.cvariables+"</td>";
        HTMLS+="</tr>";
		 HTMLS+="<tr>";
        	HTMLS+="<td>7</td>";
        	HTMLS+="<td>enteros</td>";
        	HTMLS+="<td>"+Lexico.centeros+"</td>";
        	
HTMLS+="        </tr>";
		 HTMLS+="<tr>";
        	HTMLS+="<td>8</td>";
        	HTMLS+="<td>flotantes</td>";
        	HTMLS+="<td>"+Lexico.cflotantes+"</td>";
        	
HTMLS+="        </tr>";
		 HTMLS+="<tr>";
        	HTMLS+="<td>9</td>";
        	HTMLS+="<td>cadenas</td>";
        	HTMLS+="<td>"+Lexico.ccadenas+"</td>";
        	
HTMLS+="        </tr>";
		HTMLS+=" <tr>";
        	HTMLS+="<td>10</td>";
        	HTMLS+="<td>caracteres</td>";
        	HTMLS+="<td>"+Lexico.ccaracteres+"</td>";
        	
        HTMLS+="</tr>";
		 HTMLS+="<tr>";
        	HTMLS+="<td>11</td>";
        	HTMLS+="<td>Comentarios</td>";
        	HTMLS+="<td>"+Lexico.ccomentario+"</td>";
        	
HTMLS+="        </tr>";
HTMLS+="		<tr>";
        	HTMLS+="<td>12</td>";
        	HTMLS+="<td>abrir Parentesis ( </td>";
        	HTMLS+="<td>"+Lexico.abrirParentesis+"</td>";
        HTMLS+="</tr>";
       HTMLS+="<tr>";
        	HTMLS+="<td>13</td>";
        	HTMLS+="<td>Cerrar parentesis )</td>";
        	HTMLS+="<td>"+Lexico.cerrarParentesis+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>14</td>";
        	HTMLS+="<td>=</td>";
        	HTMLS+="<td>"+Lexico.igualigual+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>15</td>";
        	HTMLS+="<td> ; </td>";
        	HTMLS+="<td>"+Lexico.puntoycoma+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>16</td>";
        	HTMLS+="<td> , </td>";
        	HTMLS+="<td>"+Lexico.cPoma+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        HTMLS+="	<td>17</td>";
        	HTMLS+="<td> : </td>";
        	HTMLS+="<td>"+Lexico.dosPuntos+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>18</td>";
        	HTMLS+="<td> * </td>";
        	HTMLS+="<td>"+Lexico.tpor+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>19</td>";
        	HTMLS+="<td> + </td>";
        	HTMLS+="<td>"+Lexico.masmas+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>20</td>";
        	HTMLS+="<td> - </td>";
        	HTMLS+="<td>"+Lexico.menosmenos+"</td>";
        HTMLS+="</tr>";
		HTMLS+="<tr>";
        	HTMLS+="<td>21</td>";
        	HTMLS+="<td>/</td>";
        	HTMLS+="<td>"+Lexico.divisiondiv+"</td>";
        HTMLS+="</tr>";
    HTMLS+="</tbody>";
HTMLS+="</table>";
HTMLS+="</body>";
HTMLS+="</html>";
ventanaMultimple.Actalizar(HTMLS);
    System.out.println(HTMLS);
    ventanaMultimple.setVisible(true);
    this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem8ActionPerformed


static public Variable buscarVariable(String nombre){
Variable temporal=null;
Variable resultado=null;
Iterator<Variable> puntero=Interfaz.tablaDeSimbolos.iterator();

while(puntero.hasNext()){
temporal=puntero.next();
if(temporal.nombre.equals(nombre)){
resultado=temporal;
}
System.out.println(temporal.Tipo+"  "+temporal.nombre+"  "+temporal.valor);
}
return resultado;
}
private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
this.ventanaResultados.inicializar();
    this.ventanaResultados.setVisible(true);
    this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem7ActionPerformed
lexico Lexico=null;
sintactico Sintactico=null;
public void compilar(String   texto){
     this.tablaDeSimbolos.clear();
     
    ListaDeErroresLexicos.clear();
    ListaDeToken.clear();
System.out.println("---------------Inicio Analisis---------------");
        try {
             Lexico=new lexico(new BufferedReader( new StringReader(texto)));
                   Lexico.setListaErrores (Interfaz.ListaDeErroresLexicos);
                   Lexico.setListaToken(ListaDeToken);
            Sintactico=new sintactico(Lexico);
            
            Sintactico.parse();
            
        } catch (Exception ex) {
            Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }
System.out.println("----------------Fin Analisis----------------");

}


//String Inicio="<html><body bgcolor=\\"#C0D9D9\\" \\" +link=\\"#000000\\" vlink=\\"magenta\\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>Reporte de Errores</strong></marquee></caption>         <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Lexema</th><th scope=\"col\" class=\"columna  a30px\">tipo de error</th><th scope=\"col\" class=\"columna a20px\">Columna</th><th scope=\"col\" class=\"columna a20px\">Fila</th></tr><tr>";
String fin="</tbody></table></center></body></html>";

String Inicio="<html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <style> table{ background:#000;color:#F9C;border: #700 solid 1px;}thead{background:#F39;padding: 3px 5px;color:#fff;font-size:1.2em;font-weight: bold;} td, th{	border-bottom: #333 solid 1px; border-right:#333 solid 1px;}tr:nth-child(even){	background:#222;}td:last-child,th:last-child{border-right:none;}tr:last-child td{border-bottom:none;}td,th{ margin: 0; padding: 3px 10px; vertical-align:top}</style> </head><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font size=20 color=\"blue\"> T</font><font color=\"#F9C\">a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>           <marquee><font color=\"#F9C\">Reporte de Errores</font></marquee>          <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><thead><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Lexema</th><th scope=\"col\" class=\"columna  a30px\">tipo de error</th><th scope=\"col\" class=\"columna a20px\">Columna</th><th scope=\"col\" class=\"columna a20px\">Fila</th></tr></thead><tr><tr><td>0</td> <td><strong>_</strong></td><td><strong>elimine esto</strong></td><td><strong>error lexico</strong></td><td>1</td> <td>20</td></tr>";
    
	

public String GenerarHTMLerroresLexicos(){
String texto2="";
texto2+=Inicio;

int contador=0;
Iterator<NodoError> d=this.ListaDeErroresLexicos.iterator();
Compilador.NodoError temporal=null;
while(d.hasNext()){
temporal=d.next();
texto2+="<tr><td>"+contador+"</td> <td><strong>"+temporal.palabra+"</strong></td><td><strong>elimine esto</strong></td><td><strong>error lexico</strong></td><td>"+temporal.columna+"</td> <td>"+temporal.linea+"</td></tr>"+"\n";
contador++;
}
texto2+=fin;
return texto2;
}


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
/*String Cadena = "<inicio>\n";
Cadena+="Print \"Hola Mundo\"; _ ?¨¨¨? \n";
Cadena+="Print var3;\n";
Cadena+="var Integer nueva=5;\n";
Cadena+="var String nueva=\"sdfasd\";\n";
Cadena+="var Float flotante=45.4;\n";
Cadena+="var Char nueva='d';\n";
Cadena+="Graficar (3, 3, var1:-5:8:7);\n";
Cadena+="Graficar (2, 4, 2:8:-10);\n";
Cadena+="Operacion (5+4 - 8.1*8/12+var1);\n";
Cadena+="Operacion (5+4-(8.1*8/12)+var1);\n";
Cadena+="//extras\n";
Cadena+="Graficar (2, 4, 2:8:-10.03);\n";
Cadena+="/* comentario línea 1\n";
Cadena+="comentario línea 2 * /\n";
Cadena+="<fin>\n";

*/
    if(Texto.getText().equals("")){
    JOptionPane.showMessageDialog(null, "abra un archivo o edite las instrucciones antes de compilar");
    }
if(direccion_dearchivo.equals("") && !Texto.getText().equals("")){
    compilar(Texto.getText());
}
if(!direccion_dearchivo.equals("") && !Texto.getText().equals("")){
    this.Guardarw();
    compilar(Texto.getText());
    this.buscarVariable(" ");
} 


//System.out.println(GenerarHTMLerroresLexicos());
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    Abrir();
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
this.Guardarw();// TODO add your handling code here:
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    Texto.setText("");
    direccion_dearchivo = "";

    // TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
    void Abrir() {
        char letra;
        String Text = "";
        try {
            JFileChooser fc9 = new JFileChooser(System.getProperty("user.dir"));
            fc9.setMultiSelectionEnabled(false);
            fc9.setFileFilter(new Filtro(true));
            fc9.showOpenDialog(this);
            File Abrir = fc9.getSelectedFile();//Devuelve el File que vamos a leerName
            fc9.setFileSelectionMode(fc9.FILES_ONLY);
            if (Abrir != null) {
                nombre = fc9.getSelectedFile().getName();
            }
            if (Abrir != null) {
                Texto.setText("");
                FileReader Fichero = new FileReader(Abrir);
                BufferedReader leer = new BufferedReader(Fichero);
                while ((Text = leer.readLine()) != null) {
                    Texto.append(Text + "\n"); //append Concatena la linea leida
                }

                direccion_dearchivo = Abrir.getAbsolutePath();
                leer.close();

            }

        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Interfaz().setVisible(true);
            }
        });
    }
    String inicio = "<html><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font ><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>Analisis Lexico </strong></marquee></caption>         <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Codigo</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Lexema</th><th scope=\"col\" class=\"columna  a30px\">Palabra reservada o constante o variable</th><th scope=\"col\" class=\"columna a20px\">Columna</th><th scope=\"col\" class=\"columna a20px\">Fila</th></tr><tr>";
    String inicioErrores = "<html><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font ><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>  Analisis De  Errores Sintactico de Las Consultas </strong></marquee></caption>         <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Codigo</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Eliminar Este lexema </th><th scope=\"col\" class=\"columna  a30px\">Se Esperaba</th><th scope=\"col\" class=\"columna a20px\">Columna</th><th scope=\"col\" class=\"columna a20px\">Fila</th></tr><tr>";
    String Final = "</tbody></table></center></html><a href=\"#tope\">De vuelta arriba</a></body>";
    String entrada = "<td>";
    String salida = "</td>";
    String abirfil = "<strong>";
    String cerrar = "</strong>";
    String primero = "<tr>";
    String segundo = "</tr>";
    String total = "";
    String Total2 = "";
    String totalERRor = "";
    String totlaTabla = "";
    String TotalReporte = "";
    ArrayList<String> datosColumna;
    ArrayList<ArrayList> filasdatos;
    ArrayList tupla;
    ArrayList tamaño_html;
    String inicioreporte = "<html><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font ><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>Analisis Lexico </strong></marquee></caption> ";
    String inicioErroresTABLA = "<html><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font ><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>  Analisis De  Errores Sintactico de Las Tablas Cargadas </strong></marquee></caption>         <table Caption=\"tokens validos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Codigo</th><th scope=\"col\" class=\"columna a20px\">Token</th><th scope=\"col\" class=\"columna  a30px\">Eliminar Este lexema </th><th scope=\"col\" class=\"columna  a30px\">Se Esperaba</th><th scope=\"col\" class=\"columna a20px\">Columna</th><th scope=\"col\" class=\"columna a20px\">Fila</th></tr><tr>";
    String inicioErroresemanticos = "<html><body bgcolor=\"#C0D9D9\" \" +link=\"#000000\" vlink=\"magenta\" alink=\"#000000\"\"text=\"#FFFFFF\" background=\"tabla.gif\"><center><u><i><font ><font size=20 color=\"blue\"> T</font><font><font size=8 >a<font><font color=\"blue\">b</font> <font><font color=\"blue\">l</font>a<font><font color=\"blue\">   </font>de <font><font color=\"blue\">T</font>oken</font></i></u></center>   <br><a href=\"principal.html\">P&aacute;pagina principal</a><br><font size=5>         <caption style=\"text-align: center;font-color:\"blue\" font-size: 25px;\"><marquee><strong>  Analisis De  Errores Semanticos de Las Consultas </strong></marquee></caption>         <table Caption=\"erores semanticos\" border=\"18\"Bgcolor=\"black\" cellspadding=\"0\" cellspacing=\"0\" width=\"100%\" class=\"futbol_c\"><caption style=\"text-align: center; font-size: 18px;\"><strong></strong></caption><tbody><tr><th scope=\"col\" class=\"columna a20px\">Contador</th><th scope=\"col\" class=\"columna a20px\">Descripcion</th>";
    String TotalErroresSemanticos = "";
    
    
    public String  GenTex_Mostrar_Ventana_de_Especificaciones(){
    String html="";
    
    
    return html;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea Texto;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
